<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

const animationDuration = 6000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    },
    chartData: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      console.log('this.chartData', this.chartData)
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
        title:{
          text:"职工服务数据",
          left: 'center',
          textStyle:{
            fontSize: 20,
            fontWeight: 'bold',
            color: '#000'
          },
        },
        tooltip: {
          trigger: 'axis',
          formatter: function(params) {
            const pacs=params[0]
            const month = pacs.name;
            const value = pacs.value;
            return month+"月:提交数量"+ value;
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            data:  this.chartData.monthlist,
            axisLabel: {
              formatter: function (value) {
                var  labal=value + '月份';
                return value; // 这里可以根据需要自定义显示的文本
              }
            },
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: '提交数量',
            type: 'bar',
            barWidth: '60%',
            data: this.chartData.monthValuelist
          }
        ]
      })
    }
  }
}
</script>
